Skip to content

Handle overlapping copyto! within a ChainedVector - #137

Open
quinnj-bot[bot] wants to merge 2 commits into
mainfrom
claude/chainedvector-copyto-overlap
Open

quinnj-bot[bot] wants to merge 2 commits into
mainfrom
claude/chainedvector-copyto-overlap

Conversation

@quinnj-bot

@quinnj-bot quinnj-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Why

A ChainedVector should give the same answers as the same data in a Vector. copyto! from a ChainedVector into itself, or from a view of itself, copied chunk by chunk without checking for overlap. When the destination range starts after the source range, it overwrote source elements before reading them:

julia> x = ChainedVector([[1, 2], [3], [4, 5]]); copyto!(x, 2, x, 1, 2)
5-element ChainedVector{Int64, Vector{Int64}}:
 1
 1
 1     # Vector gives 2
 4
 5

What changed

  • The three copyto!(dest, doffs, src, soffs, n) methods that take a ChainedVector call Base.unalias(dest, src) first, as Base's generic copyto! does. An overlapping source is copied before the write starts.

Scope

  • Out-of-range arguments still throw ArgumentError, as the existing tests expect. Vector throws BoundsError there.

Blast radius

Non-overlapping copies pay one identity check. Overlapping copies now allocate a copy of the source, which is what Base does for other arrays.

Verification

🤖 Generated with Claude Code

quinnj and others added 2 commits November 18, 2026 23:30
Fails on main; passes with the next commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copying chunk by chunk overwrote an overlapping source before reading
it, so copyto!(x, 2, x, 1, 2) repeated the first element. Call
Base.unalias(dest, src) first, as Base's generic copyto! does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@quinnj-bot
quinnj-bot Bot force-pushed the claude/chainedvector-copyto-overlap branch from 26fddfd to 0eee67e Compare November 19, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant